<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

//后台路由
Route::group(['prefix' => 'admin'], function () {
	//控制器组
	Route::group(['namespace' => 'Back'], function () {
		//品牌路由
		Route::group(['prefix' => 'brand'], function () {
			//添加品牌,可选参数id，正则约束为数字
			Route::match(['get', 'post'], 'set/{id?}', 'BrandController@set')->where('id', '[0-9]+')->name('brand.set');
			//品牌列表
			Route::match(['get', 'post'], 'list/{field?}/{order?}', 'BrandController@show')
				->where(['field' => '[A-Za-z_]+', 'order' => '[a-z]+'])->name('brand.list');
			//品牌搜索
			Route::match(['post'], 'search', 'BrandController@search')->name('brand.search');
			//为防止无限循环bug，把在search路由验证失败后的页面转到品牌列表
			Route::match(['get'], 'search', 'BrandController@show')->name('brand.search');
		});

		//ajax路由
		Route::group(['prefix' => 'ajax'], function () {
			//验证路由
			Route::match(['get', 'post'], 'validator/{name}', 'AjaxController@validator')
				->where('name', '\w+')->name('ajax.validator');
		});

		//代码生成器路由
		Route::group(['prefix' => 'code'], function () {
			//生成
			Route::match(['get', 'post'], 'generate/{type?}', 'CodeController@generate')->name('code.generate');
		});

		//配置路由
		Route::group(['prefix' => 'setting'], function () {
			//设置配置
			Route::match(['post'], 'set', 'SettingController@set')->name('setting.set');
			//ajax请求
			Route::group(['prefix' => 'ajax'], function () {
				Route::match(['post'], 'set', 'SettingController@ajaxSet')->name('setting.ajax.set');
			});
			//配置列表
			Route::match(['get'], 'list', 'SettingController@show')->name('setting.list');
			//搜索
			Route::match(['post', 'get'], 'search', 'SettingController@show')->name('setting.search');
		});

		//商品分类路由
		Route::group(['prefix' => 'category'], function () {
			//添加分类,可选参数id，正则约束为数字
			Route::match(['get', 'post'], 'set/{id?}', 'CategoryController@set')->where('id', '[0-9]+')->name('category.set');
			//分类列表
			Route::match(['get', 'post'], 'list/{field?}/{order?}', 'CategoryController@show')
				->where(['field' => '[A-Za-z_]+', 'order' => '[a-z]+'])->name('category.list');
			//分类搜索
			Route::match(['post'], 'search', 'CategoryController@search')->name('category.search');
			//为防止无限循环bug，把在search路由验证失败后的页面转到品牌列表
			Route::match(['post', 'get'], 'search', 'CategoryController@show')->name('category.search');
		});

		//重量单位路由
		Route::group(['prefix' => 'weight'], function () {
			//添加重量单位,可选参数id，正则约束为数字
			Route::match(['get', 'post'], 'set/{id?}', 'WeightUnitController@set')->where('id', '[0-9]+')->name('weight-unit.set');
			//重量单位列表
			Route::match(['get', 'post'], 'list/{field?}/{order?}', 'WeightUnitController@show')
				->where(['field' => '[A-Za-z_]+', 'order' => '[a-z]+'])->name('weight-unit.list');
			//重量单位搜索
			Route::match(['post'], 'search', 'WeightUnitController@search')->name('weight-unit.search');
			//为防止无限循环bug，把在search路由验证失败后的页面转到品牌列表
			Route::match(['get'], 'search', 'WeightUnitController@show')->name('weight-unit.search');
		});

		//商品路由
		Route::group(['prefix' => 'goods'], function () {
			//添加重量单位,可选参数id，正则约束为数字
			Route::match(['get', 'post'], 'set/{id?}', 'GoodsController@set')->where('id', '[0-9]+')->name('goods.set');
			//重量单位列表
			Route::match(['get', 'post'], 'list/{field?}/{order?}', 'GoodsController@show')
				->where(['field' => '[A-Za-z_]+', 'order' => '[a-z]+'])->name('goods.list');
			//重量单位搜索
			Route::match(['post'], 'search', 'GoodsController@search')->name('goods.search');
			//为防止无限循环bug，把在search路由验证失败后的页面转到品牌列表
			Route::match(['get'], 'search', 'GoodsController@show')->name('goods.search');
		});
	});
});
